<?php
defined('JPATH_BASE') or die();

jimport('joomla.filesystem.file'); 
jimport('joomla.filesystem.folder'); 

class JElementWord extends JElement
{ 
	
	
	function fetchElement($name, $value, &$node, $control_name)
	{ 	
		$db=JFactory::getDBO();
		$section = 'content';
		$query = 'SELECT c.id id, CONCAT_WS( "/",s.title, c.title ) AS title' .
			' FROM #__categories AS c' .
			' LEFT JOIN #__sections AS s ON s.id=c.section' .
			' WHERE c.published = 1' .
			' AND s.scope = '.$db->Quote($section).
			' ORDER BY s.title, c.title';	
		$db->setQuery($query);
		$options = $db->loadObjectList();		
		ob_start();				
		?>			
			<input style="margin:65px 0 0 0; float:left; "  type="text" id="word" />			
			<select style="margin:0 0 0 3px;" size="10 name="sectcat" id="sectcat">
				<option value="0">- Select Category -</option>
				<?php for ($i=0;$i<count($options);$i++)
				{
					$row=$options[$i];
					?>
						<option value="<?echo $row->id; ?>"><?echo '('.$row->id.') '.$row->title; ?></option>
					<?php
				}
				?>				
			</select>			
			<textarea style="" id="<?php echo $control_name.$name; ?>" name="<?php echo $control_name.'['.$name.']'; ?>" rows="8" cols="30" name="params[keysave]"><?php echo $value; ?></textarea>
				<script type="text/javascript">				
					var id="<?php echo $control_name.$name; ?>";
					window.addEvent('domready', function(){						
						$('sectcat').addEvent('dblclick',function(e){
							if(parseInt($('sectcat').value)==0)
								return false;
							var oldvalue=$(id).value;
							var newvalue="["+$('word').value+"=>"+$('sectcat').value+"]";
							$(id).value=oldvalue+"\n"+newvalue;
						});						
					});
				</script>
			<?php
		$return = ob_get_contents();
		ob_end_clean();		
		return $return;	 
	}

}
